package org.s3.project.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.s3.project.entity.AddressBook;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

/**
 * @author cfx
 * @version 1.0
 * @Description
 * @date 2025/2/9 9:37
 */
@Mapper
@Repository
public interface AddressBookMapper extends BaseMapper<AddressBook> {
    @Select("SELECT * FROM address_book WHERE user_id = #{userId}")
    List<AddressBook> selectAddressBook(int userId);
    @Insert("INSERT INTO address_book (user_id,consignee,sex,phone,province_name,city_name,district_name,detail,label) VALUES (#{user_id},#{consignee},#{sex},#{phone},#{province_name},#{city_name} ,#{district_name},#{detail},#{label})")
    int AddAddressBook(AddressBook addressBook);
    @Delete("DELETE FROM address_book WHERE id = #{id}")
    int deleteAddressBook(int id);
    @Update("UPDATE address_book SET consignee = #{consignee},sex = #{sex},phone = #{phone},province_name = #{province_name},city_name = #{city_name},district_name = #{district_name},detail = #{detail},label = #{label} WHERE id = #{id}")
    int updateAddressBook(AddressBook addressBook);

       @Update("update address_book\n" +
               "set is_default=0\n" +
               "where id != #{id} and user_id=#{userId}")
    Boolean UpdateIsDefault(@Param("userId") long userId,@Param("id") long id);
}
